﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataModel;
using System.Xml;
using System.Xml.Linq;

namespace BasicDataManagement
{
    public class InitiateDB
    {
        static OpFromDB op;

        public InitiateDB()
        {
            if (op == null)
            {
                op = OpFromDB.GetInstance();
            }
        }

        public static void InitiateCategory()
        {
            op.CreateCategory(ObjectType.Material, "肉类");
            op.CreateCategory(ObjectType.Material, "蔬菜");
            op.CreateCategory(ObjectType.Material, "主料");
            op.CreateCategory(ObjectType.Material, "水产");
            op.CreateCategory(ObjectType.Material, "配料");
            op.CreateCategory(ObjectType.Material, "饮料原料");
        }

        public static void InitiateMaterial()
        {
            op = OpFromDB.GetInstance();
            op.CreateObject(ObjectType.Material, new MaterialObject("肥猪肉", "肉类", "克"));
            op.CreateObject(ObjectType.Material, new MaterialObject("瘦猪肉", "肉类", "克"));
            op.CreateObject(ObjectType.Material, new MaterialObject("五花肉", "肉类", "克"));
            op.CreateObject(ObjectType.Material, new MaterialObject("鸡", "肉类", "克"));
            op.CreateObject(ObjectType.Material, new MaterialObject("乌鸡", "肉类", "克"));
            op.CreateObject(ObjectType.Material, new MaterialObject("西洋鸭", "肉类", "克"));

            op.CreateObject(ObjectType.Material, new MaterialObject("上海青", "蔬菜", "克"));
            op.CreateObject(ObjectType.Material, new MaterialObject("大白菜", "蔬菜", "克"));
            op.CreateObject(ObjectType.Material, new MaterialObject("小白菜", "蔬菜", "克"));
            op.CreateObject(ObjectType.Material, new MaterialObject("空心菜", "蔬菜", "克"));
            op.CreateObject(ObjectType.Material, new MaterialObject("胡萝卜", "蔬菜", "克"));

            op.CreateObject(ObjectType.Material, new MaterialObject("普通大米", "主料", "两"));
            op.CreateObject(ObjectType.Material, new MaterialObject("泰国香米", "主料", "两"));
            op.CreateObject(ObjectType.Material, new MaterialObject("河粉", "主料", "两"));
            op.CreateObject(ObjectType.Material, new MaterialObject("面粉", "主料", "两"));

            op.CreateObject(ObjectType.Material, new MaterialObject("虾", "水产", "只"));
            op.CreateObject(ObjectType.Material, new MaterialObject("花蟹", "水产", "两"));
            op.CreateObject(ObjectType.Material, new MaterialObject("生蚝", "水产", "个"));
            op.CreateObject(ObjectType.Material, new MaterialObject("鲩鱼", "水产", "两"));

            op.CreateObject(ObjectType.Material, new MaterialObject("梅菜", "配料", "两"));
            op.CreateObject(ObjectType.Material, new MaterialObject("酸菜", "配料", "两"));
            op.CreateObject(ObjectType.Material, new MaterialObject("香菇", "配料", "两"));
            op.CreateObject(ObjectType.Material, new MaterialObject("桂圆", "配料", "粒"));
            op.CreateObject(ObjectType.Material, new MaterialObject("枸杞", "配料", "克"));
            op.CreateObject(ObjectType.Material, new MaterialObject("红枣", "配料", "粒"));

            op.CreateObject(ObjectType.Material, new MaterialObject("绿豆沙原料", "饮料原料", "毫升"));
            op.CreateObject(ObjectType.Material, new MaterialObject("可乐原料", "饮料原料", "毫升"));

        }

        public static void InitiateOptionCategory()
        {
            op = OpFromDB.GetInstance();
            op.CreateCategory(ObjectType.Option, "配肉");
        }

        public static void InitiateOption()
        {
            op = OpFromDB.GetInstance();
            var oo1 = new OptionObject("白菜肉丝", "配肉", "两");
            List<Ingredient> ooi1 = new List<Ingredient>();
            ooi1.Add(new Ingredient("大白菜", "克", 50));
            ooi1.Add(new Ingredient("肥猪肉", "克", 30));
            oo1.IngredientList = ooi1;
            op.CreateObject(ObjectType.Option, oo1);

            var oo2 = new OptionObject("香菇滑稽", "配肉", "两");
            List<Ingredient> ooi2 = new List<Ingredient>();
            ooi2.Add(new Ingredient("香菇", "克", 100));
            ooi2.Add(new Ingredient("鸡", "克", 20));
            oo2.IngredientList = ooi2;
            op.CreateObject(ObjectType.Option, oo2);
        }

        public static void InitiateFixedDishCategory()
        {
            op = OpFromDB.GetInstance();
            op.CreateCategory(ObjectType.FixedDish, "粉面");
            op.CreateCategory(ObjectType.FixedDish, "蒸饭");
            op.CreateCategory(ObjectType.FixedDish, "青菜");
            op.CreateCategory(ObjectType.FixedDish, "炖盅");
            op.CreateCategory(ObjectType.FixedDish, "饮品");
        }

        public static void InitiateFixedDish()
        {
            op = OpFromDB.GetInstance();
            XElement xe = XElement.Load(@"D:\Users\LacusClyne\Documents\Visual Studio 2008\Projects\ZwxSystem\BasicDataManagement\TestData\FixedDish.xml");
            var catList = xe.Elements();
            foreach (var cat in catList)
            {
                var fdList = cat.Elements();
                foreach (var fd in fdList)
                {
                    var fdo = new FixedDishObject(fd.Attribute("name").Value, cat.Attribute("name").Value, fd.Attribute("unit").Value);
                    var ingreList = fd.Elements();
                    foreach (var ingre in ingreList)
                    {
                        var ingro = new Ingredient(ingre.Attribute("name").Value, ingre.Attribute("unit").Value, Convert.ToDouble(ingre.Attribute("dosage").Value));
                        fdo.IngredientList.Add(ingro);
                    }
                    op.CreateObject(ObjectType.FixedDish, fdo);
                }
            }
        }

        public static void InitiateComboCategory()
        {
            op = OpFromDB.GetInstance();
            op.CreateCategory(ObjectType.Combo, "饭自选套餐");
            op.CreateCategory(ObjectType.Combo, "粉面自选套餐");
            op.CreateCategory(ObjectType.Combo, "营养炖盅套餐");
        }

        public static void InitiateCombo()
        {
            op = OpFromDB.GetInstance();
            XElement xe = XElement.Load(@"D:\Users\LacusClyne\Documents\Visual Studio 2008\Projects\ZwxSystem\BasicDataManagement\TestData\Combo.xml");
            var catList = xe.Elements();
            foreach (var cat in catList)
            {
                var comboList = cat.Elements();
                foreach (var combo in comboList)
                {
                    var comboObj = new ComboObject(combo.Attribute("name").Value, cat.Attribute("name").Value, combo.Attribute("unit").Value);
                    var compList = combo.Elements();
                    foreach (var comp in compList)
                    {
                        var comCompObj = new ComboComponentObject(comp.Attribute("name").Value);
                        var ingreList = comp.Elements();
                        foreach (var ingre in ingreList)
                        {
                            var ingreObj = new Ingredient(ingre.Attribute("name").Value, ingre.Attribute("unit").Value, Convert.ToDouble(ingre.Attribute("dosage").Value));
                            comCompObj.IngredientList.Add(ingreObj);
                        }
                        comboObj.ComponentList.Add(comCompObj);
                    }
                    op.CreateObject(ObjectType.Combo, comboObj);
                }
            }
        }

        public static void InitiateReplaceableCategory()
        {
            op = OpFromDB.GetInstance();
            op.CreateCategory(ObjectType.ReplaceableDish, "清真食品");
            op.CreateCategory(ObjectType.ReplaceableDish, "成都小吃");
        }

        public static void InitiateReplaceable()
        {
            op = OpFromDB.GetInstance();
            XElement xe = XElement.Load(@"D:\Users\LacusClyne\Documents\Visual Studio 2008\Projects\ZwxSystem\BasicDataManagement\TestData\ReplaceableDish.xml");
            var catList = xe.Elements();
            foreach (var cat in catList)
            {
                var rdList = cat.Elements();
                foreach (var rd in rdList)
                {
                    var rdObj = new ReplaceableDishObject(rd.Attribute("name").Value, cat.Attribute("name").Value, rd.Attribute("unit").Value);
                    var optList = rd.Element("OptionList").Elements();
                    foreach (var opt in optList)
                    {
                        var ingreObj = new Ingredient(opt.Attribute("name").Value, opt.Attribute("unit").Value, Convert.ToDouble(opt.Attribute("dosage").Value));
                        rdObj.OptionList.Add(ingreObj);
                    }

                    var matList = rd.Element("MaterialList").Elements();
                    foreach (var mat in matList)
                    {
                        var ingreObj = new Ingredient(mat.Attribute("name").Value, mat.Attribute("unit").Value, Convert.ToDouble(mat.Attribute("dosage").Value));
                        rdObj.MaterialList.Add(ingreObj);
                    }
                    op.CreateObject(ObjectType.ReplaceableDish, rdObj);
                }
            }
        }
    }
}
